
import { Project } from "./Entity/Common/Project"
import { Result } from "./Entity/Common/Result";
import { Request } from "./Entity/Common/Request";
import { Global, GlobalSocketUser } from "./Entity/Common/Global";

/** 用户模块 */
export class SocketUser {

    /** 根据客户端标识登陆 获取 ClientToken */
    LoginWsByClient(paramster: Project, callback:Function)
    {

        if (!paramster.uuid) {
            console.error("project uuid is null");
            return;
        }

        if (!paramster.projectToken) {
            console.error("project projectToken is null");
            return;
        }

        var request = new Request(GlobalSocketUser.WsByClient.toString(),paramster);


        request.Then(e => {
            if(e.code == 200)
            {
                callback(e);
            }
            else{
                console.error(e.info)
            }

        }).Catch(a => {
            console.error("请求异常请刷新重试");
        }).Post();
    }

    /** 
     * 退出 Ws 登陆
     * token 为ServiceToken
     * 原token 仍然有效
     */
    OutLoginWs(token:string,callback:Function)
    {
        if (!token) {
            console.error("token is null");
            return;
        }

        var request = new Request(GlobalSocketUser.OutLoginWs.toString()+token)

        request.Then(e => {

            if(e.code == 200)
            {
                callback(e);
            }
            else{
                console.error(e.info)
            }

        }).Catch(a => {
            console.error("请求异常请刷新重试");
        }).Delete();

    }

}